home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / antlr / globals.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-10  |  11.8 KB  |  377 lines  |  [TEXT/MPS ]

  1. /*
  2.  * globals.c    --    File containing all variables/tables visible to all files.
  3.  *
  4.  * $Id: globals.c,v 1.13 1994/12/31 21:02:55 parrt Exp parrt $
  5.  * $Revision: 1.13 $
  6.  *
  7.  * SOFTWARE RIGHTS
  8.  *
  9.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  10.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  11.  * company may do whatever they wish with source code distributed with
  12.  * PCCTS or the code generated by PCCTS, including the incorporation of
  13.  * PCCTS, or its output, into commerical software.
  14.  * 
  15.  * We encourage users to develop software with PCCTS.  However, we do ask
  16.  * that credit is given to us for developing PCCTS.  By "credit",
  17.  * we mean that if you incorporate our source code into one of your
  18.  * programs (commercial product, research project, or otherwise) that you
  19.  * acknowledge this fact somewhere in the documentation, research report,
  20.  * etc...  If you like PCCTS and have developed a nice tool with the
  21.  * output, please mention that you developed it using PCCTS.  In
  22.  * addition, we ask that this header remain intact in our source code.
  23.  * As long as these guidelines are kept, we expect to continue enhancing
  24.  * this system and expect to make other tools available as they are
  25.  * completed.
  26.  *
  27.  * ANTLR 1.31
  28.  * Terence Parr
  29.  * Parr Research Corporation
  30.  * with Purdue University and AHPCRC, University of Minnesota
  31.  * 1989-1995
  32.  */
  33. #include <stdio.h>
  34. #ifdef __cplusplus
  35. #ifndef __STDC__
  36. #define __STDC__
  37. #endif
  38. #endif
  39. #include "set.h"
  40. #include "syn.h"
  41. #include "hash.h"
  42. #include "generic.h"
  43.  
  44. char Version[] = "1.31" ;    /* PCCTS version number */
  45. char VersionDef[] = "131";    /* same (except int equiv for preproc symbol) */
  46. char LexStartSymbol[] = "START";/* Name of starting lexical class/automaton */
  47.  
  48. char *RemapFileName = "remap.h";
  49. char *DlgFileName = "parser.dlg";
  50. char *DefFileName = "tokens.h";
  51. char *ErrFileName = "err.c";
  52. char *ModeFileName = "mode.h";
  53.  
  54. char *ParserName = DefaultParserName;
  55.  
  56. /* list of PCCTS supplied support symbols; these are renamed when more than
  57.  * one ANTLR-generated parsers are linked together to avoid name conflicts.
  58.  * Can't use '##' ANSIC preprocessor concat operator with K&R and:
  59.  *        #define zzskip    zzparser ## skip
  60.  * will not work for ANSI/C++ as 'zzparserskip' is created w/o zzparser
  61.  * being substituted--ack!!!
  62.  */
  63. char *StandardSymbols[] = {
  64. /* ANTLR stuff */
  65.     "zzStackOvfMsg",
  66.     "zzasp",
  67.     "zzaStack",
  68.     "inf_tokens",
  69.     "inf_text",
  70.     "inf_text_buffer",
  71.     "inf_text_buffer_ptr",
  72.     "inf_text_buffer_size",
  73.      "inf_labase",
  74.     "inf_last",
  75.     "inf_lap",
  76.     "zztokenLA",
  77.     "zztextLA",
  78.     "zzlap",
  79.     "zzlabase",
  80.     "zztoktext",
  81.     "zztoken",
  82.     "zzdirty",
  83.     "zzguessing",
  84.     "zzguess_start",
  85.     "zzresynch",
  86.     "zzinf_tokens",
  87.     "zzinf_text",
  88.     "zzinf_text_buffer",
  89.     "zzinf_labase",
  90.     "zzinf_last",
  91.     "zzfill_inf_look",
  92.     "zzFAIL",
  93.     "zzsave_antlr_state",
  94.     "zzrestore_antlr_state",
  95.     "zzsyn",
  96.     "zzset_el",
  97.     "zzset_deg",
  98.     "zzedecode",
  99.     "_zzsetmatch",
  100.     "_zzmatch",
  101.     "_inf_zzgettok",
  102.     "zzconsumeUntil", 
  103.     "zzconsumeUntilToken",
  104.     "_zzmatch_wsig",
  105.     "_zzsetmatch_wsig",
  106.     "_zzmatch_wdfltsig",
  107.     "_zzsetmatch_wdfltsig",
  108.     "zzdflthandlers",
  109. /* DLG stuff */
  110.     "zzreal_line",
  111.     "zzcharfull",
  112.     "zzerr",
  113.     "zzlextext",
  114.     "zzbegexpr",
  115.     "zzendexpr",
  116.     "zzbufsize",
  117.     "zzbegcol",
  118.     "zzendcol",
  119.     "zzline",
  120.     "zzchar",
  121.     "zzbufovf",
  122.     "zzrdstream",
  123.     "zzrdfunc",
  124.     "zzrdstr",
  125.     "zzclose_stream",
  126.     "zzsave_dlg_state",
  127.     "zzrestore_dlg_state",
  128.     "zzmode",
  129.     "zzskip",
  130.     "zzmore",
  131.     "zzreplchar",
  132.     "zzreplstr",
  133.     "zzgettok",
  134.     "zzadvance",
  135.     "zzerrstd",
  136.     "zzerr_in",
  137.     "zzconstr_attr",
  138.     "zzempty_attr",
  139.     "zzerraction",
  140.     "zztokens",            /* list of token regular expressions */
  141.     "dfa",
  142.     "accepts",
  143.     "actions",
  144.     NULL        /* must be present */
  145. };
  146.  
  147. /* list of PCCTS supplied support functions; these are renamed when more than
  148.  * one ANTLR-generated parsers are linked together to avoid name conflicts.
  149.  */
  150. char *ASTSymbols[] = {
  151.     "AST",
  152.     "zzast_sp",
  153.     "zzastStack",
  154.     "zzlink",
  155.     "zzastnew",
  156.     "zzsubchild",
  157.     "zzsubroot",
  158.     "zzpre_ast",
  159.     "zzfree_ast",
  160.     "zztmake",
  161.     "zzdup_ast",
  162.     "zztfree",
  163.     "zzdouble_link",
  164.     NULL        /* must be present */
  165. };
  166.  
  167. /* Current ambiguity examination information */
  168. int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;
  169. char *CurAmbigbtype;
  170.  
  171.  
  172.                         /* M e t h o d  T a b l e s */
  173. /*
  174.  * The following tables are used to fill syntax diagram nodes with the correct
  175.  * function pointers for computing FIRST sets and printing themselves.
  176.  */
  177.  
  178. /* fpTraverse[node type] == pointer to function that calculates trees
  179.  * representing the FIRST sets for that node (maintains spatial info).
  180.  * We use 'struct _tree' not 'tree' due to a g++ 2.4.3 bug.
  181.  */
  182. #ifdef __cplusplus
  183. struct _tree *(*fpTraverse[NumNodeTypes+1])(... /* Node *, int, set * */) = {
  184.     NULL,
  185.     (struct _tree *(*)(...)) tJunc,
  186.     (struct _tree *(*)(...)) tRuleRef,
  187.     (struct _tree *(*)(...)) tToken,
  188.     (struct _tree *(*)(...)) tAction
  189. };
  190. #else
  191. Tree *(*fpTraverse[NumNodeTypes+1])() = {
  192.     NULL,
  193.     tJunc,
  194.     tRuleRef,
  195.     tToken,
  196.     tAction
  197. };
  198. #endif
  199.  
  200. /* fpReach[node type] == pointer to function that calculates FIRST set for
  201.  * that node. (r stands for reach).  We use 'struct _set' not 'set'
  202.  * due to a g++ 2.4.3 bug.
  203.  */
  204. #ifdef __cplusplus
  205. struct _set (*fpReach[NumNodeTypes+1])(... /* Node *, int, set * */) = {
  206.     NULL,
  207.     (struct _set (*)(...)) rJunc,
  208.     (struct _set (*)(...)) rRuleRef,
  209.     (struct _set (*)(...)) rToken,
  210.     (struct _set (*)(...)) rAction
  211. };
  212. #else
  213. set (*fpReach[NumNodeTypes+1])() = {
  214.     NULL,
  215.     rJunc,
  216.     rRuleRef,
  217.     rToken,
  218.     rAction
  219. };
  220. #endif
  221.  
  222. /* fpPrint[node type] == pointer to function that knows how to print that node. */
  223. #ifdef __cplusplus
  224. void (*fpPrint[NumNodeTypes+1])(... /* Node * */) = {
  225.     NULL,
  226.     (void (*)(...)) pJunc,
  227.     (void (*)(...)) pRuleRef,
  228.     (void (*)(...)) pToken,
  229.     (void (*)(...)) pAction
  230. };
  231. #else
  232. void (*fpPrint[NumNodeTypes+1])() = {
  233.     NULL,
  234.     pJunc,
  235.     pRuleRef,
  236.     pToken,
  237.     pAction
  238. };
  239. #endif
  240.  
  241. char *decodeJType[] = {
  242.     "invalid",
  243.     "aSubBlk",
  244.     "aOptBlk",
  245.     "aLoopBlk",
  246.     "EndBlk",
  247.     "RuleBlk",
  248.     "Generic",
  249.     "EndRule",
  250.     "aPlusBlk",
  251.     "aLoopBegin"
  252. };
  253.  
  254.  
  255.                             /* H a s h  T a b l e s */
  256.  
  257. Entry    **Tname,            /* Table of all token names (maps name to tok num)*/
  258.         **Texpr,            /* Table of all token expressions
  259.                                (maps expr to tok num) */
  260.         **Rname,            /* Table of all Rules (has ptr to start of rule) */
  261.         **Fcache,            /* Cache of First/Follow Computations */
  262.         **Tcache;            /* Tree cache; First/Follow for permute trees */
  263. Entry    **Elabel;            /* Table of all element label names */
  264. Entry    **Sname;            /* Signal names */
  265.  
  266.  
  267.                             /* V a r i a b l e s */
  268.  
  269. int        EpToken=0;            /* Imaginary Epsilon token number */
  270. int        WildCardToken=0;
  271. int        CurFile= -1;        /* Index into FileStr table */
  272. char    *CurRule=NULL;        /* Pointer to current rule name */
  273. RuleEntry *CurRuleNode=NULL;/* Pointer to current rule node in syntax tree */
  274. char    *CurRetDef=NULL;    /* Pointer to current return type definition */
  275. char    *CurParmDef=NULL;    /* Pointer to current parameter definition */
  276. Junction *CurRuleBlk=NULL;    /* Pointer to current block node for enclosing block */
  277. ListNode *CurExGroups=NULL;    /* Current list of exception groups for rule/alts */
  278. ListNode *CurElementLabels=NULL;
  279. int        CurBlockID=0;        /* Unique int for each block */
  280. int        CurAltNum=0;
  281. Junction *CurAltStart = NULL;    /* Junction node that starts the alt */
  282. int        NumRules=0;            /* Rules are from 1 to n */
  283. FILE    *output=NULL;        /* current parser output file */
  284. FILE    *input=NULL;        /* current grammar input file */
  285. char    *FileStr[MaxNumFiles];/* Ptr to array of file names on command-line */
  286. int        NumFiles=0;            /* current grammar file number */
  287. #ifdef __cplusplus
  288. void    (**fpTrans)(...),    /* array of ptrs to funcs that translate nodes */
  289.          (**fpJTrans)(...);    /*  ... that translate junctions */
  290. #else
  291. void    (**fpTrans)(),        /* array of ptrs to funcs that translate nodes */
  292.          (**fpJTrans)();        /*  ... that translate junctions */
  293. #endif
  294. int        **FoStack;            /* Array of LL_k ptrs to stacks of rule numbers */
  295. int        **FoTOS;            /* FOLLOW stack top-of-stack pointers */
  296. Junction *SynDiag = NULL;    /* Pointer to start of syntax diagram */
  297. int        BlkLevel=1;            /* Current block level.  Set by antlr.g, used by
  298.                              * scanner to translate $i.j attributes */
  299. set        reserved_positions;    /* set of token positions reserved by '#token T=i' cmds */
  300. set        all_tokens;            /* set of all token types */
  301. set        imag_tokens;        /* set of all imaginary token types (EpToken, errclasses...) */
  302. set        tokclasses;            /* set of all token class token types */
  303. ListNode *ForcedTokens = 0;    /* list of token_id/token_num pairs to remap */
  304. ListNode *MetaTokenNodes=NULL; /* list of meta token refs such as token classes etc... */
  305. int        *TokenInd=NULL;        /* an indirection level between token num and position
  306.                              * of that token def in TokenStr and ExprStr */
  307. int        LastTokenCounted=0;    /* ==TokenNum if no token renumbering (same as old TokenNum) */
  308. int        TokenNum=TokenStart;
  309. char    **TokenStr=NULL;    /* map token # to token name */
  310. char    **ExprStr=NULL;        /* map token # to expr */
  311. Junction **RulePtr=NULL;    /* map rule # to RuleBlk node of rule */
  312. ListNode *ExprOrder=NULL;    /* list of exprs as they are found in grammar */
  313. ListNode *BeforeActions=NULL;/* list of grammar actions before rules */
  314. ListNode *AfterActions=NULL;/* list of grammar actions after rules */
  315. ListNode *LexActions=NULL;    /* list of lexical actions */
  316. ListNode **Cycles=NULL;        /* list of cycles (for each k) found when
  317.                                doing FOLLOWs */
  318. ListNode *eclasses=NULL;    /* list of error classes */
  319. ListNode *tclasses=NULL;    /* list of token classes */
  320. LClass     lclass[MaxLexClasses]; /* array of lex class definitions */
  321. int         CurrentLexClass;    /* index into lclass */
  322. int         NumLexClasses=0;    /* in range 1..MaxLexClasses (init 0) */
  323.  
  324. char    *HdrAction=NULL;    /* action defined with #header */
  325. FILE    *ErrFile;            /* sets and error recovery stuff */
  326. FILE    *DefFile=NULL;        /* list of tokens, return value structs, setwd defs */
  327. int        CannotContinue=FALSE;
  328. int        OutputLL_k = 1;        /* LL_k for parsing must be power of 2 */
  329. int        action_file;        /* used to track start of action */
  330. int        action_line;
  331. int        FoundGuessBlk=0;    /* there is a (...)? block somewhere in grammar */
  332. int        FoundException=0;    /* there is an exception somewhere in grammar */
  333. int        pLevel=0;            /* print Level */
  334. int        pAlt1,pAlt2;        /* print "==>" in front of these alts */
  335.  
  336. /* C++ output stuff */
  337. FILE    *Parser_h,            /* where subclass of ANTLRParser goes */
  338.         *Parser_c;            /* where code for subclass of ANTLRParser goes */
  339. char    Parser_h_Name[MaxFileName+1] = "";
  340. char    Parser_c_Name[MaxFileName+1] = "";
  341. ListNode *class_actions=NULL;/* list of actions inside the #class {...} defs */
  342. char    CurrentClassName[MaxRuleName]="";
  343. int        no_classes_found=1;
  344. char    *UserTokenDefsFile;
  345. int        UserDefdTokens=0;    /* found #tokdefs? */
  346. char    *OutputDirectory=TopDirectory;
  347. ExceptionGroup *DefaultExGroup = NULL;
  348. int        NumSignals = NumPredefinedSignals;
  349.  
  350.  
  351.                     /* C m d - L i n e  O p t i o n s */
  352.  
  353. int        LL_k=1;                /* how many tokens of full lookahead */
  354. int        CLL_k= -1;            /* how many tokens of compressed lookahead */
  355. int        PrintOut = FALSE;    /* print out the grammar */
  356. int        PrintAnnotate = FALSE;/* annotate printout with FIRST sets */
  357. int        CodeGen=TRUE;        /* Generate output code? */
  358. int        LexGen=TRUE;        /* Generate lexical files? (tokens.h, parser.dlg) */
  359. int        GenAST=FALSE;        /* Generate AST's? */
  360. int        GenANSI=FALSE;        /* Generate ANSI code where necessary */
  361. int        GenExprSets=TRUE;    /* use sets not (LA(1)==tok) expression lists */
  362. int        GenCR=FALSE;        /* Generate cross reference? */
  363. int        GenLineInfo=FALSE;    /* Generate # line "file" stuff? */
  364. int        TraceGen=FALSE;        /* Generate code to trace rule invocation */
  365. int        elevel=1;            /* error level for ambiguity messages */
  366. int        GenEClasseForRules=0;/* don't generate eclass for each rule */
  367. int        TreeResourceLimit= -1;/* don't limit tree resource */
  368. int        DemandLookahead = 0;/* demand/delayed lookahead or not */
  369. char    *RulePrefix = "";    /* prefix each generated rule with this */
  370. char    *stdpccts = "stdpccts.h";/* where to generate std pccts include file */
  371. int        GenStdPccts = 0;    /* don't gen stdpccts.h? */
  372. int        ParseWithPredicates = 1;
  373. int        WarningLevel = 1;
  374. int        HoistPredicateContext = 0;
  375. int        GenCC = 0;            /* Generate C++ output */
  376. int        DontCopyTokens = 1;    /* in C++ don't copy ANTLRToken passed to ANTLR */
  377.